import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
// import { Context } from '../typings/app';


export default (appInfo: EggAppInfo) => {
  const config: PowerPartial<EggAppConfig> = {
    keys: appInfo.name + '_1586754643883_6758',
    sessionSecret: 'hLrp5i2NeWfTqDYV',
    saltPassword: '4SPN3UfzwE6Dkyhh',
    jwt: {
      secret: new Buffer("xiaoxiami-secret", "base64").toString()
    },
    middleware: ['errorHandler', 'header'],
    header: {
      match: '/xxm',
    },
    aminer: {
      key: '347a53b9383f3c266569765175aebc48.gNI4aWZ0NGfrMRv7'
    },
    baiduAI: {
      Key: 'NCi6I2s24rAOMmEtYQsQZc55',
      Secret: 'DEblESUGYRRaoZFhPZTUHKxU90S0pAA0'
    },
    chuangkit: {
      AppId: '4d0b48bc62354968b37b737d4bcda888',
      Secret: '94F9821D477B16DEBCD8EE1ECCDC158B'
    },
    alicloud: {
      AccessKey: 'LTAI5tMmvRT9rSTaHDyXKLCY',
      Secret: 'GNtn4HA6jeVgq0d9SFjanUEBpF6k2P'
    },
    sequelize: {
      dialect: 'mysql',
      host: 'dev.elephmusic.com',
      // host: '127.0.0.1',
      port: 3306,
      username: 'root',
      // 密码
      password: 'haoxiaomi123_KK',
      database: 'shop',
      define: {
        underscored: false,  // 禁止驼峰式字段默认转为下划线
        charset: 'utf8mb4',
        timestamps: true
      },
      dialectOptions: {
        charset: 'utf8mb4'
      },
    },
    redis: {
      client: {
        port: 6379, // Redis port
        host: '127.0.0.1', // Redis host
        password: '',
        db: 0,
      },
    },
    bodyParser: {
      enable: true,
      encoding: 'utf8',
      formLimit: '100kb',
      jsonLimit: '100kb',
      strict: true,
      // @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
      queryString: {
        arrayLimit: 100,
        depth: 5,
        parameterLimit: 1000,
      },
      enableTypes: ['json', 'form', 'text'],
      extendTypes: {
        text: ['text/xml', 'application/xml'],
      },
    },
    skipAuthentication: false,
    security: {
      csrf: {
        enable: false,
      },
      // 白名单
      domainWhiteList: ['*']
    },
    cluster: {
      listen: {
        path: '',
        port: 5101,
        hostname: '0.0.0.0',
      }
    },
    cors: {
      origin: 'http://localhost:8080',
      allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
      // 下面这条加上才能共享跨域session，同时前端ajax请求也要加上响应的参数
      credentials: true,
    },

  };
  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  // 支付配置
  const payConfig = {
    // appid: 'wxf2a3edb735f16910',  // 公众号ID
    // mchid: '1584950371', // 微信商户号
    // partnerKey: '5f173a57849e4413a45bb445516500eb', // partnerKey
  };
  // 小程序登录地址
  const wxApp = {
    // appid: payConfig.appid,
    // secret: '00fe2ed303960b6b98a226054d92eb1f',
    login: 'https://api.weixin.qq.com/sns/jscode2session'
  };
  // oss
  const oss = {
    region: 'oss-cn-beijing',
    accessKeyId: 'LTAI4FheKoWN9uKCATD6qg17',
    accessKeySecret: '5OJzuFL71KruUJZC53nYXMoa6QWLPo',
    bucket: 'xmmi',
  };

  // payInfo
  const payInfo = {
    domain: 'https://wx.yumimiao.cn',
    // domain: 'http://ivk7rt.natappfree.cc',
    notify_url: '/wx/order/pay/callback',
  };

  // 打印机
  const feiyun = {
    url: 'http://api.feieyun.cn',
    fei_user: 'hpysirius@gmail.com',
    fei_ukey: 'c4yVx4kCufFBzbeH'
  }

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
    payConfig,
    wxApp,
    oss,
    payInfo,
    feiyun
  };
};
